﻿using System;
using System.Collections.Generic;
using System.Runtime.InteropServices;
using System.Text;

namespace Avatar.ClientDevice
{
    internal static class SunVoteWrapper
    {
        [UnmanagedFunctionPointer(CallingConvention.StdCall)]
        public delegate void ConnectEventCallbackDelegate(int iBaseID, int iMode, string sInfo);
        [UnmanagedFunctionPointer(CallingConvention.StdCall)]
        public delegate void HDParamEventCallbackDelegate(int iBaseID, int iMode, string sInfo);
        [UnmanagedFunctionPointer(CallingConvention.StdCall)]
        public delegate void VoteEventCallbackDelegate(int iBaseID, int iMode, string sInfo);
        [UnmanagedFunctionPointer(CallingConvention.StdCall)]
        public delegate void KeyEventCallbackDelegate(string KeyID, int iMode, float Time, string sInfo);
        //public delegate void KeyEventCallbackDelegate(int iBaseID, int KeyID, string keySN, int iMode, float Time, string sInfo);
#if Android
            const string DllName = "libSunVoteSDK.so";
#elif __IOS__
        const string DllName = "__Internal";
#elif __MACOS__
        const string DllName = "libSunVoteSDK_x64.dylib";
#else
        const string DllName = "SunVoteSDK.dll";
#endif

        [DllImport(DllName, CallingConvention = CallingConvention.Cdecl)]
        internal static extern int Connect(int iMode, string sParam);

        [DllImport(DllName, CallingConvention = CallingConvention.Cdecl)]
        internal static extern int Disconnect(int baseId);

        [DllImport(DllName, CallingConvention = CallingConvention.Cdecl)]
        internal static extern int WriteHDParam(int BaseID, int iMode, string sSetting);

        [DllImport(DllName, CallingConvention = CallingConvention.Cdecl)]
        internal static extern int ReadHDParam(int BaseID, int iMode);

        [DllImport(DllName, CallingConvention = CallingConvention.Cdecl)]
        internal static extern int VoteStart(int iMode, string sSetting);

        //[DllImport(DllName, CallingConvention = CallingConvention.Cdecl)]
        //internal static extern int VoteStart2(int iBaseID, int iMode, string sSetting);


        [DllImport(DllName, CallingConvention = CallingConvention.Cdecl)]
        internal static extern int VoteStop();

        //[DllImport(DllName, CallingConvention = CallingConvention.Cdecl)]
        //internal static extern int VoteStop2(int iBaseID);

        [DllImport(DllName, CallingConvention = CallingConvention.Cdecl)]
        internal static extern int SetLogOn(int isEnable);

        [DllImport(DllName, CallingConvention = CallingConvention.Cdecl)]
        internal static extern int License(int Mode, string sInfo);


        [DllImport(DllName, CallingConvention = CallingConvention.Cdecl)]
        internal static extern void SetConnectEventCallBack(ConnectEventCallbackDelegate ConnectEventCallback);

        [DllImport(DllName, CallingConvention = CallingConvention.Cdecl)]
        internal static extern void SetHDParamEventCallBack(HDParamEventCallbackDelegate HDParamEventCallback);

        [DllImport(DllName, CallingConvention = CallingConvention.Cdecl)]
        internal static extern void SetVoteEventCallBack(VoteEventCallbackDelegate VoteEventCallback);

        [DllImport(DllName, CallingConvention = CallingConvention.Cdecl)]
        internal static extern void SetKeyEventCallBack(KeyEventCallbackDelegate KeyEventCallback);
    }
}
